import QtQuick 1.1
import com.nokia.meego 1.0

Item {
    id:slider
    property real zoomScale: 0.9
    property real value: zoomScale

    anchors.fill: parent
    Flickable {
        id: flickable; anchors.fill: parent; clip: true
        contentWidth: imageContainer.width; contentHeight: imageContainer.height
        boundsBehavior: Flickable.StopAtBounds;

        Item {
            id: imageContainer
            width: Math.max(zoomDemot.width * zoomDemot.scale, flickable.width);
            height: Math.max(zoomDemot.height * zoomDemot.scale, flickable.height);

            Image {
                id: zoomDemot; source: demoty_picture; scale: zoomScale
                anchors.centerIn: parent; smooth: !flickable.movingVertically
                visible: (zoomDemot.status==Image.Ready); asynchronous: true
                sourceSize.width: 500; sourceSize.height: parseInt(demoty_height_500)

                PinchArea {
                    property double __oldZoom

                    anchors.fill: parent

                    function calcZoomDelta(zoom, percent) {
                        return Math.max(0.94,zoom + Math.log(percent)/Math.log(2));
                    }

                    onPinchStarted: {
                        __oldZoom = zoomDemot.scale
                    }

                    onPinchUpdated: {
                        zoomDemot.scale = calcZoomDelta(__oldZoom, pinch.scale)
                    }

                    onPinchFinished: {
                        zoomDemot.scale = calcZoomDelta(__oldZoom, pinch.scale)
                        if(pinch.scale<1.02) flickable.returnToBounds();
                    }
                }
                MouseArea {
                    id: mousearea
                    anchors.fill: parent
                    onClicked: {demotElement.flipped=!demotElement.flipped;
                        console.log("klikanie");
                    }
                    onDoubleClicked: zoomDemot.scale=1;
                }
            }
        }
    }
}
